import json
import re

# 构建响应字典：处理第一个文件的键并存储响应
response_dict = {}
with open('./tgt_0_37499_s2t/ifeval_input_data_n_test_s2t_by_znlin_added_by_20250424/llmasr_decode/result.jsonl', 'r') as f1:
    for line in f1:
        data = json.loads(line)
        original_key = data['key']
        # 转换键，例如将math401_110转为math_110
        # original_key = re.sub(r'^math\d+', 'math', original_key)
        response_dict[original_key] = data['response']

# 处理第二个文件并合并数据
with open('./tgt/ifeval_input_data.jsonl.t', 'r') as f2, \
     open('./tgt_0_37499_s2t/ifeval.jsonl', 'w') as out:
    for line in f2:
        data = json.loads(line)
        current_key = data['key']
        # 获取对应的响应，若无则设为空字符串
        data['predict'] = response_dict.get(current_key, '')
        out.write(json.dumps(data, ensure_ascii=False) + '\n')